class MagicBox02<T>(item:T) {
    var available = false
    private var subject:T = item
    fun fetch():T?{
        return subject.takeIf { available }
    }
}

class Boy02(val name:String, val age: Int)
class Dog02(val weight:Int)

fun main() {
    val magicBox:MagicBox02<Boy02> = MagicBox02(Boy02("jack", 80))
    val magicBox1:MagicBox02<Dog02> = MagicBox02(Dog02(90))
    magicBox.available = true
    magicBox.fetch()?.run {
        println("you find $name")
    }
}